package image;

public class RGBArray implements MorphImage {


	public final int[][] red;
	public final int[][] green;
	public final int[][] blue;
	public final int[][] red_old;
	public final int[][] green_old;
	public final int[][] blue_old;
	final int imageSizeY;
	final int imageSizeX;


	public RGBArray(int[][] red, int[][] green, int[][] blue) {
		//TODO dimension aggre check
		this.imageSizeX = red.length;
		this.imageSizeY = red[0].length;
		this.red_old = red;
		this.green_old = green;
		this.blue_old = blue;
		this.red = new int[imageSizeX][imageSizeY];
		this.green = new int[imageSizeX][imageSizeY];
		this.blue = new int[imageSizeX][imageSizeY];
		for (int x = 0; x < imageSizeX; x++) {
			for (int y = 0; y < imageSizeY; y++) {
				this.red[x][y] = red[x][y];
				this.green[x][y] = green[x][y];
				this.blue[x][y] = blue[x][y];
			}
		}
	}

	@Override
	public int getImageSizeY() {
		return imageSizeY;
	}

	@Override
	public int getImageSizeX() {
		return imageSizeX;
	}

	@Override
	public void draw(int x, int y, double[][] oldBox, double[][] newBox) {
		int p1_red;
		int p1_green;
		int p1_blue;
		int p2_red;
		int p2_green;
		int p2_blue;
		int p3_red;
		int p3_green;
		int p3_blue;
		int p4_red;
		int p4_green;
		int p4_blue;
		int x1;
		int y1;
		int x2;
		int y2;
		red[x][y] =
				(int) ((1.0/((x2-x1)*(y2-y1)))*(
				p1_red*(x2-x)*(y2-y)+
				p4_red*(x-x1)*(y2-y)+
				p2_red*(x2-x)*(y-y1)+
				p3_red*(x-x1)*(y-y1)
				));
		green[x][y] =
				(int) ((1.0/((x2-x1)*(y2-y1)))*(
				p1_green*(x2-x)*(y2-y)+
				p4_green*(x-x1)*(y2-y)+
				p2_green*(x2-x)*(y-y1)+
				p3_green*(x-x1)*(y-y1)
				));
		blue[x][y] =
				(int) ((1.0/((x2-x1)*(y2-y1)))*(
				p1_blue*(x2-x)*(y2-y)+
				p4_blue*(x-x1)*(y2-y)+
				p2_blue*(x2-x)*(y-y1)+
				p3_blue*(x-x1)*(y-y1)
				));

	}

}
